Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: generate types for mappings when int8 is used as id #1934

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

shiyasmohd
Copy link
Contributor

No description provided.

Copy link

changeset-bot bot commented Jan 31, 2025

🦋 Changeset detected

Latest commit: 6cc2a1c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@graphprotocol/graph-cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

cloudflare-workers-and-pages bot commented Jan 31, 2025

Deploying graph-tooling with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6cc2a1c
Status: ✅  Deploy successful!
Preview URL: https://ce29b2ea.graph-tooling.pages.dev
Branch Preview URL: https://shiyasmohd-int8-as-id-types.graph-tooling.pages.dev

View logs

Copy link
Contributor

github-actions bot commented Jan 31, 2025

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@graphprotocol/graph-cli 0.96.0-alpha-20250211013356-6cc2a1c7813a896ba22df3dbf73fb96965d84a87 npm ↗︎ unpkg ↗︎

@shiyasmohd shiyasmohd self-assigned this Feb 1, 2025
@YaroShkvorets
Copy link
Collaborator

Is this PR finished?
graph build with these changes doesn't work if id type is set to Int8.
Codegen needs to be adjusted.

@shiyasmohd
Copy link
Contributor Author

@YaroShkvorets PR is finished now

@YaroShkvorets YaroShkvorets self-requested a review February 11, 2025 02:51
@YaroShkvorets
Copy link
Collaborator

YaroShkvorets commented Feb 11, 2025

@shiyasmohd
Codegen now works, but scaffolded subgraph doesn't.

Steps to reproduce:

  1. Init new subgraph:
graph init test test --from-contract 0xdAC17F958D2ee523a2206206994597C13D831ec7 --protocol ethereum --network mainnet --index-events
  1. Replace id: Bytes! for Issue entity in the GraphQL schema with id: Int8!
  2. Run graph codegen - works
  3. Run graph build - fails with
 Compile subgraphERROR TS2322: Type '~lib/@graphprotocol/graph-ts/common/collections/Bytes' is not assignable to type 'i64'.

     event.transaction.hash.concatI32(event.logIndex.toI32())
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 in src/contract.ts(30,5)

Basically need to generate different code for Int8 that constructs unique 64-bit id for our event:

let entity = new Issue(
    event.transaction.hash.concatI32(event.logIndex.toI32())
  )

I guess we could just hash this thing and take first 8 bytes in these cases.

Or we could construct something from block number, transaction index and event index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants